package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.daoman.Assess;
import com.example.daoman.Floor;
import com.example.mapper.AssessMapper;
import com.example.service.AssessService;
import com.example.utils.GetSession;
import com.example.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class AssessServiceImpl extends ServiceImpl<AssessMapper, Assess> implements AssessService {

    @Autowired
    private AssessMapper assessMapper;


//        //    查询个人的考核信息

    @Override
    public Message getUserAssess() {

        try {
            int uid = GetSession.get().getId();
            Map<String, Object> map = new HashMap<>();
            map.put("userId", uid);
            List<Assess> allAssessList = assessMapper.getMyAssessList(map);
            return Message.out(200, "查询一个", allAssessList);
        } catch (Exception e) {
            return null;
        }
    }


    //    管理员添加考核记录

    @Override
    public Message addAssess(Assess assess) {
        Map<String, Object> map = new HashMap<>();
        map.put("uid", assess.getUid());
        map.put("rid", assess.getRid());
        map.put("fid", assess.getFid());
        map.put("content", assess.getContent());
        map.put("deal", assess.getDeal());
        map.put("rootId", assess.getRootId());
        map.put("time", assess.getTime());
        boolean b = assessMapper.addAssess(map);
        return Message.out(200, "添加", b);
    }


    //    删除学员的考核记录

    @Override
    public Message removeAssess(int id) {
        boolean b = assessMapper.removeAssess(id);
        return Message.out(200, "删除操作", b);
    }


    //    查询所有的考核信息

    @Override
    public Message getAllAssessList(List<Floor> floorList) {
        Map<String,Object> map = new HashMap<>();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (Floor f:floorList){
            arrayList.add(f.getId());
        }
        map.put("fid",arrayList);
        List<Assess> allAssessList = assessMapper.getAllAssessList(map);
        return Message.out(200, "查询所哟考核信息", allAssessList);
    }
}
